﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Demo9_1_2
{
    internal class Program
    {
        static Person people = new Person();
        static Student student = new Student();
        static void Main(string[] args)
        {
            Console.WriteLine("1231");
          
            Task.Run(() =>
            {
                lock (people)
                {

                    Console.WriteLine($"TID={Environment.CurrentManagedThreadId}进入person");
                    Thread.Sleep(1000);
                    lock (student)
                    {

                        Console.WriteLine($"TID2={Environment.CurrentManagedThreadId}进入student");
                        Console.WriteLine();
                    }
                }

            });
            Task.Run(() =>
            {
                lock (student)
                {

                    Console.WriteLine($"TID3={Environment.CurrentManagedThreadId}进入student");
                    Thread.Sleep(1000);
                    lock (people)
                    {

                        Console.WriteLine($"TID4={Environment.CurrentManagedThreadId}进入people");
                        Console.WriteLine();
                    }
                }


            });
            Console.ReadLine();
        }
    }

    public class Person { 
      public string Name { get; set; }
    
    }
    public class Student
    {
        public string Name { get; set; }

    }

}
